//
//  NewViewController.m
//  Behinders
//
//  Created by sigure on 14-11-3.
//  Copyright (c) 2014年 sigure. All rights reserved.
//

#import "NewViewController.h"
#import "musicanInfo.h"
#define startX 30
#define startY 80
#define DIAMETER 70

@interface NewViewController ()
@property (nonatomic, strong) NSArray *musicanList;
@end

@implementation NewViewController

- (NSArray *)musicanList
{
    if (!_musicanList) {
        // 1. 从mainBundle加载
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *path = [bundle pathForResource:@"musican.plist" ofType:nil];
        //        _appList = [NSArray arrayWithContentsOfFile:path];
        
        NSArray *array = [NSArray arrayWithContentsOfFile:path];
        // 将数组转换成模型，意味着self.appList中存储的是LFAppInfo对象
        // 1. 遍历数组，将数组中的字典依次转换成AppInfo对象，添加到一个临时数组
        // 2. self.appList = 临时数组..
        NSMutableArray *arrayM = [NSMutableArray array];
        
        for (NSDictionary *dict in array) {
            [arrayM addObject:[musicanInfo musicanWithDict:dict]];
        }
        
        _musicanList = arrayM;
    }
    return _musicanList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"最新幕后人";
    self.view.backgroundColor=MTColor(220.0, 220.0, 220.0, 1.0);
    for (int i=0; i<3; i++) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(startX/2,startY+200*i, MAINWIDTH-startX, 180)];
        view.backgroundColor=[UIColor whiteColor];
        [self.view addSubview:view];
    }
    
    for (int i=0; i<3; i++)
    {
        musicanInfo *musican = self.musicanList[i];
        
    
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(startX, 20+startY+200*i, DIAMETER,DIAMETER )];
        
        imageView.layer.masksToBounds =YES;
        imageView.backgroundColor =MTColor(220.0, 220.0, 220.0, 1.0);
        imageView.layer.cornerRadius =DIAMETER/2;
        imageView.image = musican.image ;
        
        UILabel *name =[[UILabel alloc] initWithFrame:CGRectMake(20+startX+DIAMETER, 20+startY+200*i, MAINWIDTH,16)];
        name.font = [UIFont systemFontOfSize:16];
        name.textColor = [UIColor blackColor];
        if([musican.other isEqual:@""])
        {
            name.text = musican.name;
            
        }
        else
        {
            NSString *string = [[NSString alloc] initWithFormat:@"（%@）", musican.other];
            name.text = [musican.name stringByAppendingString:string];
        }

        
        [self.view addSubview:imageView];
        [self.view addSubview:name];
    }
    
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
